<?php include '_init_.php';?>
<?php include 'page_header.php';?>
<div id="main"><!-- start #main //-->
<div id="tita"> <!-- start #tita //-->
<?php define('ORDER_NAVIGATOR_ITEM','贈品查詢');?>
<?php include 'navigator_order_search.php';?>
<?php define('ORDER_MENU_CURRENT_ITEM','贈品');?>
<?php include 'order_search_menu.php';?>
<?php

$act = isset($_REQUEST['act'])?$_REQUEST['act']:'';
$condition = isset($_REQUEST['condition'])?$_REQUEST['condition']:'';
if($act == 'search')
{
	$condition = "";
	if(strlen($_REQUEST['start']) > 0)
	{
		$condition .= sprintf("TO_DAYS(`created`) >= TO_DAYS('%s') and ",date('Y-m-d',strtotime($_REQUEST['start'])));
	}
	if(strlen($_REQUEST['end']) > 0)
	{
		$condition .= sprintf("TO_DAYS(`created`) <= TO_DAYS('%s') and ",date('Y-m-d',strtotime($_REQUEST['end'])));
	}
	if(count($_REQUEST['gift_name']) > 0)
	{
		$add_gif_filter = false;
		$gif_condition = '';
		foreach($_REQUEST['gift_name'] as $tmpData)
		{
			if(strlen(trim($tmpData)) > 0)
				$gif_condition .= sprintf("`gift_list`='%%%s%%' or ",$tmpData);
			$add_gif_filter = true;
		}
		if($add_gif_filter)
		{
			$gif_condition = substr($gif_condition,0,strlen($gif_condition) - 4);
			$condition .= sprintf("(%s) and ",$gif_condition);
		}
	}
	if(strlen($_REQUEST['status']) > 0)
	{
		$condition .= sprintf("`status` = '%s' and ",$_REQUEST['status']);
	}
	if(strlen($condition) > 0)
	{
		$condition = substr($condition,0,strlen($condition) - 4);
	}
	/*
	$link = sprintf("search_list.php?condition=%s",urlencode($condition));
	header('Location:'.$link);
	exit();
	*/
}

?>
<form action="searche.php">
<input type="hidden" name="act" value="search"/>
<div id="mainf" class="clearfix"><!-- start #maine //-->

<div class="mainf-3">
<ul>
      <li class="maine-1c">
       日期<input type="text" class="maine-keyink datepicker" name="start" value="<?php echo isset($_REQUEST['start'])?$_REQUEST['start']:'';?>">到<input type="text" class="maine-keyink datepicker" name="end" value="<?php echo isset($_REQUEST['end'])?$_REQUEST['end']:'';?>"></li>
       </ul>
 </div>
<div class="mainf-3">
<ul>
      	 <?php
        	$dtPhotoSize = new DataTable(constant('DB_TABLE_PHOTO_SIZE'));
        	$data_list = $dtPhotoSize->get_list('','sort_index');
        	
        	$_REQUEST['gift_name'] = isset($_REQUEST['gift_name']) && is_array($_REQUEST['gift_name'])?$_REQUEST['gift_name']:array();
        	foreach($data_list as $tmpData)
        	{
        		$checked = in_array($tmpData['id'],$_REQUEST['gift_name'])?"checked='checked'":'';
        		echo sprintf('<li class="mainf-1i"> <input type="checkbox" " name="gift_name[]" value="%d" %s>&nbsp;%s</li></li>',Util::html_safe($tmpData['id']),$checked,Util::html_safe($tmpData['name']));
        	}
        ?>
       <?php
        	$dtGift = new DataTable(constant('DB_TABLE_GIFT'));
        	$data_list = $dtGift->get_list('','name');
        	foreach($data_list as $tmpData)
        	{
        		$checked = in_array($tmpData['id'],$_REQUEST['gift_name'])?"checked='checked'":'';
        		echo sprintf('<li class="mainf-1i"> <input type="checkbox" " name="gift_name[]" value="%d"  %s>&nbsp;%s</li></li>',Util::html_safe($tmpData['id']),$checked,Util::html_safe($tmpData['name']));
        	}
        ?>
       </ul>
   
     </div>
<div class="mainf-3">
<ul>
      <li class="mainf-1c">
       <input type="radio"  name="status" value='close' <?php if(isset($_REQUEST['status']) && $_REQUEST['status'] == 'close' ){echo "checked='checked'";}?>/>
       結案
       </li>
       <li class="mainf-1c">
       <input type="radio"  name="status" value='new' <?php if(isset($_REQUEST['status']) && $_REQUEST['status'] == 'new' ){echo "checked='checked'";}?>/>
       未結案
       </li>
       </ul>
   
     </div>
<div class="mainf-4">
<ul>
     <li class="maina-1d"><a href="#" onclick="document.forms[0].submit();return false;"><img src="images/search-btn.gif" width="81" height="29" /></a></li>
   </ul>
     </div>
     </div><!-- end #maine //-->
     </form>
          <?php 
     if(isset($_REQUEST['act']) || isset($_REQUEST['p']))
     {
     	 include('search_list.php');
     }
     ?>
</div><!-- end #main //-->

</div><!-- end #all //-->

</body>
</html>